namespace CIS.Customer
{
    using CISLib;
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class OtherCustomerNewsPaperPage : Page
    {
        protected Button AddBtn;
        protected Button delBtn;
        protected Image iBtnCustomer;
        protected ImageButton iBtnGray8;
        protected ImageButton iBtnOrange0;
        protected ImageButton iBtnOrange1;
        protected ImageButton iBtnOrange2;
        protected ImageButton iBtnOrange3;
        protected ImageButton iBtnOrange4;
        protected ImageButton iBtnOrange5;
        protected ImageButton iBtnOrange6;
        protected ImageButton iBtnOrange7;
        protected Label lbSelectedPaper;
        protected ListBox PaperLB;
        protected Label paperSummary;
        protected DropDownList paperTypeDdl;
        protected UserPrincipal Principal = null;
        protected ImageButton returnImgBtn;

        private void AddBtn_Click(object sender, EventArgs e)
        {
            if (!this.IsExistItem(this.paperTypeDdl.SelectedItem.Text, this.PaperLB))
            {
                ManageCustomer.InsertNewCustomerNewsPaper(new Guid(base.Request.QueryString["CustomerId"]), this.paperTypeDdl.SelectedValue);
                ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "InsertPaper", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, ManageCustomer.GetCustomerBasicInfoViaId(new Guid(base.Request.QueryString["CustomerId"])).Name);
                this.DateBind();
            }
        }

        private string choosePageTitle(string pageType)
        {
            if (pageType == "1")
            {
                return "《上海贝尔阿尔卡特》";
            }
            if (pageType == "2")
            {
                return "《伙伴》";
            }
            if (pageType == "3")
            {
                return "《方案与服务》";
            }
            if (pageType == "4")
            {
                return "《阿尔卡特电信技术展望》";
            }
            return "";
        }

        private void DateBind()
        {
            CustomerNewsPaper[] customerNewsPaper = ManageCustomer.GetCustomerNewsPaperAryViaId(new Guid(base.Request.QueryString["CustomerId"]));
            this.PaperLB.Items.Clear();
            for (int i = 0; i < customerNewsPaper.Length; i++)
            {
                this.PaperLB.Items.Add(new ListItem(this.choosePageTitle(customerNewsPaper[i].NewsPaperType), customerNewsPaper[i].CustomerNewsPaperId.ToString()));
            }
        }

        private void delBtn_Click(object sender, EventArgs e)
        {
            try
            {
                ManageCustomer.RemoveCustomerNewsPaperViaId(new Guid(this.PaperLB.SelectedValue));
                this.PaperLB.Items.Remove(this.PaperLB.Items[this.PaperLB.SelectedIndex]);
                this.DateBind();
            }
            catch
            {
            }
        }

        private void FillPage()
        {
            this.DateBind();
        }

        private void iBtnOrange0_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerBasicInfoPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange1_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoPersonalPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange2_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoPreferencePage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange3_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoHealthCostumePage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange4_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoTravelPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange5_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoStudyPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange6_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoWorkPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void iBtnOrange7_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                string customerId = base.Request.QueryString["CustomerId"].ToString();
                base.Response.Redirect("~/CIS/Customer/CustomerInfoFamilyPage.aspx?IsModify=True&CustomerId=" + customerId.ToString(), true);
            }
            catch (Exception)
            {
            }
        }

        private void InitializeComponent()
        {
            this.iBtnOrange0.Click += new ImageClickEventHandler(this.iBtnOrange0_Click);
            this.iBtnOrange1.Click += new ImageClickEventHandler(this.iBtnOrange1_Click);
            this.iBtnOrange2.Click += new ImageClickEventHandler(this.iBtnOrange2_Click);
            this.iBtnOrange3.Click += new ImageClickEventHandler(this.iBtnOrange3_Click);
            this.iBtnOrange4.Click += new ImageClickEventHandler(this.iBtnOrange4_Click);
            this.iBtnOrange5.Click += new ImageClickEventHandler(this.iBtnOrange5_Click);
            this.iBtnOrange6.Click += new ImageClickEventHandler(this.iBtnOrange6_Click);
            this.iBtnOrange7.Click += new ImageClickEventHandler(this.iBtnOrange7_Click);
            this.paperTypeDdl.SelectedIndexChanged += new EventHandler(this.paperTypeDdl_SelectedIndexChanged);
            this.AddBtn.Click += new EventHandler(this.AddBtn_Click);
            this.delBtn.Click += new EventHandler(this.delBtn_Click);
            this.returnImgBtn.Click += new ImageClickEventHandler(this.returnImgBtn_Click);
            base.Load += new EventHandler(this.Page_Load);
        }

        private void InitPage()
        {
            this.SetFrom();
            this.SetFromImage();
            this.paperTypeDdl.Items.Clear();
            ListItem item1 = new ListItem();
            item1.Text = "《上海贝尔阿尔卡特》";
            item1.Value = "1";
            ListItem item2 = new ListItem();
            item2.Text = "《伙伴》";
            item2.Value = "2";
            ListItem item3 = new ListItem();
            item3.Text = "《方案与服务》";
            item3.Value = "3";
            ListItem item4 = new ListItem();
            item4.Text = "《阿尔卡特电信技术展望》";
            item4.Value = "4";
            this.paperTypeDdl.Items.Add(item1);
            this.paperTypeDdl.Items.Add(item2);
            this.paperTypeDdl.Items.Add(item3);
            this.paperTypeDdl.Items.Add(item4);
            this.paperSummary.Text = "《上海贝尔阿尔卡特》报，每半月一期，简要、快速地报道公司在各方面的进展，展示公司形象，适合各层次的客户。";
        }

        private bool IsExistItem(string itemValue, ListBox tmpList)
        {
            for (int i = 0; i < tmpList.Items.Count; i++)
            {
                if (itemValue == tmpList.Items[i].Text)
                {
                    return true;
                }
            }
            return false;
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
            this.Principal = this.Context.User as UserPrincipal;
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.InitPage();
                this.FillPage();
            }
        }

        private void paperTypeDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.paperTypeDdl.SelectedValue == "1")
            {
                this.paperSummary.Text = "《上海贝尔阿尔卡特》报，每半月一期，简要、快速地报道公司在各方面的进展，展示公司形象，适合各层次的客户。";
            }
            else if (this.paperTypeDdl.SelectedValue == "2")
            {
                this.paperSummary.Text = "《伙伴》杂志，每季度一期，以专题专刊形式，报道公司在重点业务领域的领先概念、成就、解决方案等，展示公司与客户良好的合作伙伴关系，适合客户中的中高层管理人员。";
            }
            else if (this.paperTypeDdl.SelectedValue == "3")
            {
                this.paperSummary.Text = "《方案与服务》月刊，每月一期，介绍公司重点推出的解决方案、维护知识、客户培训、质量和客户满意信息等，适合客户中的建设、运维人员、相关部门的具体工作人员等。";
            }
            else if (this.paperTypeDdl.SelectedValue == "4")
            {
                this.paperSummary.Text = "《阿尔卡特电信技术展望》中文版，每季度一期，是阿尔卡特全球出版的技术推广杂志，介绍阿尔卡特在电信技术领域的领先概念和解决方案，适合客户中的中高层管理人员和设计研究院的人员。";
            }
        }

        private void returnImgBtn_Click(object sender, ImageClickEventArgs e)
        {
            base.Response.Redirect("~/CIS/Customer/CustomerInfoOtherPage.aspx?IsModify=True&CustomerId=" + base.Request.QueryString["CustomerId"].ToString(), true);
        }

        private void SetFrom()
        {
            string language = this.Session["language"].ToString();
            string path = base.Server.MapPath("~/CIS/LanguageConfig.xml");
            this.AddBtn.Text = ManageSystemConfig.GetSystemSetLanguage("OtherCustomerNewsPaperPage", "AddBtn", language, path);
            this.lbSelectedPaper.Text = ManageSystemConfig.GetSystemSetLanguage("OtherCustomerNewsPaperPage", "lbSelectedPaper", language, path);
            this.delBtn.Text = ManageSystemConfig.GetSystemSetLanguage("OtherCustomerNewsPaperPage", "delBtn", language, path);
        }

        private void SetFromImage()
        {
            switch (this.Session["language"].ToString())
            {
                case "cn":
                    this.iBtnCustomer.ImageUrl = "../images/title_customerinfo.jpg";
                    this.iBtnOrange0.ImageUrl = "../images/title_CustomerInfo_lable_1_orange.jpg";
                    this.iBtnOrange1.ImageUrl = "../images/title_CustomerInfo_lable_2_orange.jpg";
                    this.iBtnOrange2.ImageUrl = "../images/title_CustomerInfo_lable_3_orange.jpg";
                    this.iBtnOrange3.ImageUrl = "../images/title_CustomerInfo_lable_4_orange.jpg";
                    this.iBtnOrange4.ImageUrl = "../images/title_CustomerInfo_lable_5_orange.jpg";
                    this.iBtnOrange5.ImageUrl = "../images/title_CustomerInfo_lable_6_orange.jpg";
                    this.iBtnOrange6.ImageUrl = "../images/title_CustomerInfo_lable_7_orange.jpg";
                    this.iBtnOrange7.ImageUrl = "../images/title_CustomerInfo_lable_8_orange.jpg";
                    this.iBtnGray8.ImageUrl = "../images/title_CustomerInfo_lable_9_Gray.jpg";
                    break;

                case "en":
                    this.iBtnCustomer.ImageUrl = "../images/title_customerinfoEn.jpg";
                    this.iBtnOrange0.ImageUrl = "../images/title_CustomerInfoEn_lable_1_orange.jpg";
                    this.iBtnOrange1.ImageUrl = "../images/title_CustomerInfoEn_lable_2_orange.jpg";
                    this.iBtnOrange2.ImageUrl = "../images/title_CustomerInfoEn_lable_3_orange.jpg";
                    this.iBtnOrange3.ImageUrl = "../images/title_CustomerInfoEn_lable_4_orange.jpg";
                    this.iBtnOrange4.ImageUrl = "../images/title_CustomerInfoEn_lable_5_orange.jpg";
                    this.iBtnOrange5.ImageUrl = "../images/title_CustomerInfoEn_lable_6_orange.jpg";
                    this.iBtnOrange6.ImageUrl = "../images/title_CustomerInfoEn_lable_7_orange.jpg";
                    this.iBtnOrange7.ImageUrl = "../images/title_CustomerInfoEn_lable_8_orange.jpg";
                    this.iBtnGray8.ImageUrl = "../images/title_CustomerInfoEn_lable_9_Gray.jpg";
                    break;
            }
        }
    }
}

